package com.woniuxy.microsportsserver.sleepmag.controller;

import com.woniuxy.common.bean.PageDto;
import com.woniuxy.common.bean.ResultMsg;
import com.woniuxy.microsportsserver.bean.SleepAnalysisInfo;
import com.woniuxy.microsportsserver.bean.SleepInfo;
import com.woniuxy.microsportsserver.sleepmag.service.ISleepService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/sleep")
@RestController
public class SleepController {
    @Resource
    private ISleepService sleepService;


    //查询页面一数据步数的总和
    @GetMapping(value="/all",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg findAll(SleepInfo SleepInfo , Integer pageNum, Integer pageSize){
        ResultMsg resultMsg = new ResultMsg();
        PageDto pageDto = sleepService.findAll(SleepInfo,pageNum, pageSize);
        if (pageDto == null) {
            return resultMsg.setCode(10000).setMessage("系统繁忙，请稍后再试");
        }
        return resultMsg.setCode(200).setMessage("查询成功").setData(pageDto);
    }

    //近一年睡眠平均数
    @GetMapping(value = "/sleepAvg",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg sleepAvgList(){
        List<SleepAnalysisInfo> datas = sleepService.findAvgSleepValue();
        return new ResultMsg().setCode(200).setMessage("操作成功").setData(datas);
    }
    //睡眠占比
    @GetMapping(value = "/sleepPercentage",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg sleepPercentage(){
        List<SleepAnalysisInfo> datas = sleepService.findSleepPercentage();
        return new ResultMsg().setCode(200).setMessage("操作成功").setData(datas);
    }

}
